package com.boat.sample.ddd.interfaces.assembler;

import com.boat.boat.support.api.dto.account.AccountInfoRsp;
import com.boat.sample.ddd.api.dto.CancelUserTaskReq;
import com.boat.sample.ddd.api.dto.FindAccountInfoRsp;
import com.boat.sample.ddd.api.dto.FindUserRsp;
import com.boat.sample.ddd.api.dto.RegisterReq;
import com.boat.sample.ddd.api.dto.RegisterRsp;
import com.boat.sample.ddd.domain.system.entity.User;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.json.JSONUtil;

public class UserAssembler {
	public static User toUser(RegisterReq request) {
		User user = new User();
		BeanUtil.copyProperties(request, user, CopyOptions.create().ignoreError());
		return user;
	}
	
	public static RegisterRsp toRegisterRsp(User user) {
		RegisterRsp rsp = new RegisterRsp();
		BeanUtil.copyProperties(user, rsp, CopyOptions.create().ignoreError());
		return rsp;
	}

	public static FindUserRsp toFindUserRsp(User user) {
		FindUserRsp rsp = new FindUserRsp();
		BeanUtil.copyProperties(user, rsp, CopyOptions.create().ignoreError());
		return rsp;
	}
	
	public static CancelUserTaskReq toCancelUserReq( String jobParam) {
		CancelUserTaskReq param = new CancelUserTaskReq();
    	if(JSONUtil.isTypeJSONObject(jobParam)) {
    		param = JSONUtil.toBean(jobParam, CancelUserTaskReq.class);
    	}
    	return param;
	}
	
	public static FindAccountInfoRsp toFindAccountInfoRsp(AccountInfoRsp accountInfoRsp) {
		FindAccountInfoRsp findAccountInfoRsp = new FindAccountInfoRsp();
		findAccountInfoRsp.setUserId(accountInfoRsp.getUserId());
		findAccountInfoRsp.setName(accountInfoRsp.getName());
		return findAccountInfoRsp;
	}
	
}
